package com.ftx.common.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Set;

/**
 * Created by fengtingxin on 2019/6/3.
 * redis连接池工具类
 */

public class RedisPoolUtils {

    @Resource
    private JedisPool redisPool;

    /**
     * 得到jedis连接
     * @return
     */
    private Jedis getConnection(){
        return redisPool.getResource();
    }

    public void set(String key,String value){
        getConnection().set(key,value);
    }

    public String get(String key){
        return getConnection().get(key);
    }

    public Long lPush(String key,String value){
        return getConnection().lpush(key,value);
    }

    public String lpop(String key){
        return getConnection().lpop(key);
    }

    public Set<String> smembers(String key){
        return getConnection().smembers(key);
    }

    public Boolean exists(String key){
        return getConnection().exists(key);
    }

    public Long hset(String key,String field,String value){
        return getConnection().hset(key,field,value);
    }

    public String hget(String key,String field){
        return getConnection().hget(key,field);
    }

    public Map<String, String> hgetAll(String key){
        return getConnection().hgetAll(key);
    }

    public Set<String> keys(String pattern){
        return getConnection().keys(pattern);
    }

    public Long del(String key){
        return getConnection().del(key);
    }
}
